package com.wifi.a007.wifiFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.wifi.a007.LogPrint;
import com.wifi.a007.R;
import com.wifi.a007.ViewName;
import com.wifi.a007.db.Word;

import org.litepal.crud.DataSupport;

import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.List;

import okhttp3.internal.Util;


public class EnglishWordFragment extends Fragment {

    private RecyclerView  recyclerView;
    private WordAdapter   wordAdapter;
    private List<Word>  mWordList = new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.english_word_fragment_layout,container,false);


        init(view);
        return view;
    }


    private  void init(View view){
        LinearLayoutManager layoutManager=new LinearLayoutManager(getActivity());
        // layoutManager.setOrientation(LinearLayoutManager.ve);水平布局
//什么都不做就是从上到下的布局
        //StaggeredGridLayoutManager layoutManager=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);

    wordAdapter =new WordAdapter(mWordList);
    recyclerView =(RecyclerView)view.findViewById(R.id.word_List_view);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(wordAdapter);
    initData();

    }


    private  void initData(){


        //mWordList.clear();

     queyWordLocal();



    }


    private  void queyWordLocal(){

        List<Word> outList = DataSupport.findAll(Word.class);

        if(outList.size() > 0){


            for(Word word : outList){

                mWordList.add(word);
            }
            wordAdapter.notifyDataSetChanged();

        }else{

            LogPrint.toast(ViewName.mContext,"查看是否录入单词");
            mWordList.add(new Word("good","good","good","good","good","good","good","good"));


        }



    }



}
